home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPANS.ZIP / CR2LF.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  1KB  |  53 lines

  1. // cr2lf.cpp -- Convert carriage returns to line feeds
  2.  
  3. #include <iostream.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #define CR 13  // ASCII carriage return
  9. #define LF 10  // ASCII line feed
  10.  
  11. main(int argc, char *argv[])
  12. {
  13.   FILE *fpin, *fpout;
  14.   unsigned char c, lf = LF;
  15.   int nout;
  16.  
  17.   if (argc < 3) {
  18.     cout << "ERROR: No file names";
  19.     exit(1);
  20.   }
  21.   fpin = fopen(argv[1], "rb");
  22.   if (!fpin) {
  23.     cout << "ERROR: File not found";
  24.     exit(2);
  25.   }
  26.   fpout = fopen(argv[2], "wb");
  27.   if (!fpout) {
  28.     cout << "ERROR: Can't create output file";
  29.     exit(3);
  30.   }
  31.   while (fread(&c, 1, 1, fpin) > 0) {
  32.     if (c == CR)
  33.         nout = fwrite(&lf, 1, 1, fpout);
  34.     else if (c != LF)
  35.         nout = fwrite(&c, 1, 1, fpout);
  36.     if (nout != 1) {
  37.         cout << "ERROR: Writing to disk";
  38.         exit(4);
  39.     }
  40.   }
  41.   fclose(fpin);
  42.   fclose(fpout);
  43.   exit(0);
  44. }
  45.  
  46.  
  47. // Copyright (c) 1990 by Tom Swan. All rights reserved
  48. // Revision 1.00    Date: 12/06/1990   Time: 10:01 am
  49.  
  50. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  51. // Converted for Borland C++ 2.0
  52.  
  53.